//
//  HTRetweetStatus.swift
//  weibo
//
//  Created by JonsonLiu on 16/4/21.
//  Copyright © 2016年 liujonson. All rights reserved.
//

import UIKit
import SnapKit
class HTRetweetStatus: UIView {

    
    var bottomCons : Constraint?
    
    var statusViewModel : HTStatsCellViewModel?{
    
        didSet{
            turnLable.text = statusViewModel?.retweetText
            
            bottomCons?.uninstall()
            
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0{
            
                
//                pictureView.snp_makeConstraints(closure: { (make) -> Void in
//                    make.size.equalTo(statusViewModel!.retweetPictureViewSize)
//                })
                
              
                
                pictureView.dataInfo = (pic_urls,statusViewModel!.retweetPictureViewSize)
                
                pictureView.hidden = false
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    bottomCons = make.bottom.equalTo(pictureView).offset(HMStatusCellMargin).constraint
                })
            }else{
            
                pictureView.hidden = true
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    bottomCons = make.bottom.equalTo(turnLable).offset(HMStatusCellMargin).constraint
                })
            }
            
        }
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
       
        addSubview(turnLable)
        addSubview(pictureView)
        
        turnLable.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(self).offset(HMStatusCellMargin)
        }
        
        //图片约束
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(turnLable)
            
            make.top.equalTo(turnLable.snp_bottom).offset(HMStatusCellMargin)
            
//           make.size.equalTo(CGSizeMake(100, 100))
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            
           bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(HMStatusCellMargin).constraint
        }
        
    }

    
    private lazy var turnLable : UILabel =  {
    
        let lable = UILabel()
        lable.textColor = UIColor.darkGrayColor()
        lable.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * HMStatusCellMargin
        lable.numberOfLines = 0
        lable.font = UIFont.systemFontOfSize(HTstatusCellFont)
        
        return lable
    }()
    
    private lazy var pictureView : HTStatusPictrueView = HTStatusPictrueView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
    
}
